package dk.pun.aot.client.widget;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import dk.pun.aot.client.dice.DiceRoll;

public class DiceRollPopup extends Composite {

	private static DiceRollPopupUiBinder uiBinder = GWT.create(DiceRollPopupUiBinder.class);

	interface DiceRollPopupUiBinder extends UiBinder<Widget, DiceRollPopup> {}

	@UiField Label titleLabel;
	@UiField Label dicePoolLabel;
	@UiField Label diceRollsLabel;
	@UiField Label resultLabel;

	public DiceRollPopup(DiceRoll diceRoll) {
		initWidget(uiBinder.createAndBindUi(this));
		this.titleLabel.setText(diceRoll.getTitle());
		String dicePoolLabel = diceRoll.getDicePoolType().toString();
		if (diceRoll.getModifier() != 0) {
			dicePoolLabel += " + " + String.valueOf(diceRoll.getModifier());
		}
		this.dicePoolLabel.setText(dicePoolLabel);
		this.diceRollsLabel.setText(diceRoll.getRolls());
		String result = String.valueOf(diceRoll.getResult());
		if (diceRoll.getDifficultyType() != null) {
			result += "  (" + diceRoll.getDifficultyType().toString() + ")";
		}
		this.resultLabel.setText(result);
	}
}
